<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2025/8/20 星期三
  Time: 13:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE html>
<html>

<head>
    <base href="${pageContext.request.contextPath}/" />
    <title>襄阳蓝芯智能化办公系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="static/bootstrap-3.3.5/css/bootstrap.css" rel="stylesheet">
    <link href="static/bootstrapvalidator/css/bootstrapValidator.css"
          rel="stylesheet">

    <script src="static/jquery/jquery-1.10.2.min.js"></script>
    <script src="static/bootstrap-3.3.5/js/bootstrap.js"></script>
    <script src="static/bootstrapvalidator/js/bootstrapValidator.js"></script>

</head>
<body>

<BR><BR><BR>
<div class="col-md-6 col-md-offset-2">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <h4 class="panel-title">修改密码</h4>
        </div>
        <div class="panel-body">
            <form action="hr/zz-account/updatePassword" id="myform" method="post"
                  class="form-horizontal" role="form">
                <div class="form-group col-md-12">
                    <label for="oldPassword" class="col-md-4 control-label">原密码</label>
                    <div class="col-md-8">
                        <input type="password" id="oldPassword" name="oldPassword" class="form-control"
                               placeholder="请输入原密码">
                    </div>
                </div>
                <div class="form-group col-md-12">
                    <label for="newPassword" class="col-md-4 control-label">新密码</label>
                    <div class="col-md-8">
                        <input type="password" id="newPassword" name="newPassword" class="form-control"
                               placeholder="请输入新密码">
                    </div>
                </div>
                <div class="form-group col-md-12">
                    <label for="newPassword2" class="col-md-4 control-label">确认密码</label>
                    <div class="col-md-8">
                        <input type="password" id="newPassword2" name="newPassword2" class="form-control"
                               placeholder="请输入确认密码">
                    </div>
                </div>
                <div class="form-group col-md-12">
                    <div class="col-md-8  col-md-offset-4">
                        <button type="button" id="updatebtn" class="btn btn-success">确认修改</button>
                        <button type="reset" id="resetbtn" class="btn btn-default">取消操作</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>









<script type="text/javascript">
    $(document).ajaxError(function(event,xhr) {
        if(xhr.status=="403"){//没有权限
            document.location.href = xhr.getResponseHeader("url");
        }else if(xhr.status!="200"){
            //alert("服务器错误!");
            console.log("服务器错误!");
        }
    });
</script>

</body>


<script type="text/javascript">
    $(document).ready(function() {
        $("#myform").bootstrapValidator({
            message : 'This value is not valid',
            feedbackIcons : {/*input状态样式图片*/
                valid : 'glyphicon glyphicon-ok',
                invalid : 'glyphicon glyphicon-remove',
                validating : 'glyphicon glyphicon-refresh'
            },
            fields : {
                oldPassword : {
                    validators : {
                        notEmpty : {/*非空提示*/
                            message : '原密码不能为空'
                        },
                        remote:{
                            url:'hr/zz-account/checkOldPassword',
                            delay:500,
                            type:'post',
                            message:'原密码不正确',
                            data:function (validator){
                                return{
                                    'oldPassword':$("#oldPassword").val()
                                }
                            }
                        },
                        stringLength : {
                            min : 6,
                            max : 20,
                            message : '原密码长度在6-20位'
                        }
                    }
                },
                newPassword : {
                    validators : {
                        notEmpty : {/*非空提示*/
                            message : '新密码不能为空'
                        },
                        stringLength : {
                            min : 6,
                            max : 20,
                            message : '新密码长度需在6-20位'
                        },
                        different : {
                            field : 'oldPassword',
                            message : '新密码与原密码相同'
                        }
                    }
                },
                newPassword2 : {
                    validators : {
                        notEmpty : {/*非空提示*/
                            message : '新密码不能为空'
                        },
                        identical : {
                            field : 'newPassword',
                            message : '两次输入的密码不相符'
                        }
                    }
                }
            },
            submitHandler : function(validator, form, submitButton) {
                validator.defaultSubmit();
            }
        });

        $("#resetbtn").click(function() {
            $("#myform").data("bootstrapValidator").resetForm();
        });

        $("#updatebtn").click(function() {
            $('#myform').data("bootstrapValidator").validate();
            if($('#myform').data("bootstrapValidator").isValid()){
                $("#myform")[0].submit();
            }

        });
        $("#newPassword").blur(function() {
            if($("#newPassword").val()!=$("#newPassword2").val()){
                $('#myform').data("bootstrapValidator").updateStatus("newPassword2",  "INVALID", "identical" );
            }else{
                $('#myform').data("bootstrapValidator").updateStatus("newPassword2",  "NOT_VALIDATED",  null );
            }
        });
    });
</script>
</html>
